import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { IToolButton } from '@/base-ui/tool-bar';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';
// import { ColumnProps } from 'antd/es/table'
const { Option } = Select;

const { Search } = Input;

/**/

export const kind = [
  {
    label: '鸡爪',
    value: '1'
  },
  { label: '鸡翅', value: '2' },
  { label: '鸡脖', value: '3' },
  { label: '鸡胸', value: '4' },
  { label: '鸡爪', value: '5' },
  { label: '内脏', value: '6' },
  { label: '整鸡', value: '7' },
  { label: '鸡腿', value: '8' },
  { label: '其他', value: '9' }
];

/* 搜索区域 */
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '篮子编号',
    name: 'basketNo',
    placeholder: '请输入篮子编号'
  },
  {
    type: 'input' as Itype,
    label: '批次',
    name: 'batch',
    placeholder: '请输入批次'
  },
  {
    type: 'input' as Itype,
    label: '品种',
    name: 'breed',
    placeholder: '请输入品种'
  },
  {
    type: 'input' as Itype,
    label: '等级',
    name: 'grade',
    placeholder: '请输入等级'
  },
  {
    type: 'input' as Itype,
    label: '订单号',
    name: 'indent',
    placeholder: '请输入订单号'
  },
  {
    type: 'input' as Itype,
    label: '部位',
    name: 'kind',
    placeholder: '请输入部位'
  },
  {
    type: 'input' as Itype,
    label: '重量',
    name: 'weight',
    placeholder: '请输入重量'
  },
  {
    type: 'rangepicker' as Itype,
    label: '日期',
    name: 'date',
    otherOptions: {
      placeholder: ['开始日期', '结束日期']
    }
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];
export const addFormConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '产品名称',
    placeholder: '请输入产品名称'
  },
  {
    type: 'input' as Itype,
    label: '供应商',
    placeholder: '请输入供应商'
  },

  {
    type: 'select' as Itype,
    label: '件数',
    placeholder: '请选择件数区间',
    options: [
      { label: '1000件以下', value: 'value1' },
      { label: '1000-5000件', value: 'value2' },
      { label: '5000-20000件', value: 'value3' },
      { label: '20000件以上', value: 'value4' }
    ]
  },
  {
    type: 'input' as Itype,
    label: '收货商',
    placeholder: '请输入收货商'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    placeholder: '请输入备注'
  }
];
/* 工具栏区域 */

// 选择器配置
export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('part');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10
      }}
    >
      <Select
        defaultValue={Options[0].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null}></Option>
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e: string) => {
          // 清空输入框之后，再次搜索，出现的是初始化时候的数据
          if (e === '') {
            http
              .get('/server/basketSlaughter/list/1/20')
              .then((res: { data: { records: any } }) => {
                props.dataSource(res.data.records);
              });
            return;
          }
          switch (searchid) {
            case 'part': {
              http(`/server/basketSlaughter/getByPart/${e}`).then(
                (res: { data: any }) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
const Options = [{ label: '部位', value: 'part', onClick: (e: any) => {} }];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          /* onClick={() => onMoreSearchClick(false)} */
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <>
          <Button
            type="link"
            size="middle"
            onClick={() => {
              props.setisMoreSearchShow(true);
              props.setsearchMore(true);
            }}
          >
            高级检索
            <RightOutlined style={{ marginLeft: '1px' }} />
          </Button>
        </>
      )}
    </Space>
  );
};

// 按钮组
export const buttonGroup: IToolButton[] = [
  { type: 'create', text: '新增记录', isShow: true, onClick: () => {} },
  { type: 'delete', text: '批量删除', isShow: true, onClick: () => {} },
  { type: 'import', text: '导入', isShow: true, onClick: () => {} },
  { type: 'export', text: '导出', isShow: true, onClick: () => {} }
];

//复选框的接口
export interface DataType {
  id: number;
  name: string;
  age: number;
  address: string;
}
